<?php

class COneBytePerCharString extends CString {
	var $Buffer;
	
	function Init($buffer) {
		$this->Buffer = $buffer;
	}
	
	function Length() { return strlen($this->Buffer); }
	
	function IteratorClass() {
		CAbstract('COneBytePerCharString::IteratorClass()', $this);
	}
	
	function &Characters($from, $len) {
		$iteClass = $this->IteratorClass();
		$ite = &new $iteClass($this, $from, $len);
		return $ite;
	}
	
	function Substring($from, $len) {
		$x = substr($this->Buffer, $from, $len);
		$class = get_class($this);
		return new $class($x);
	}
}

class COneBytePerCharIterator extends CCharIterator {
	var $Str;
	var $From; var $Length;
	var $Cur = 0;
	
	function Init(&$str, $from, $len) {
		$this->Str = &$str;
		$this->From = $from;
		$this->Length = min($len, $str->Length());
	}
	
	function NextChar() {
		if ($this->Cur >= $this->Length)
			return null;
		
		$c = $this->ByteToChar($this->Str->Buffer{$this->From + $this->Cur});
		$this->Cur++;
		return $c;
	}
	
	function ByteToChar($x) {
		CAbstract('COneBytePerCharIterator::ByteToChar()', $this);
	}
}

class COneBytePerCharEncoder extends CBufferEncoder {
	function ReplacementBytes() {
		return '?';
	}
}

?>